package quickup;

import java.awt.Frame;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class AuthorizationDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	JTextField _uid = new javax.swing.JTextField();
	JPasswordField _pwd = new javax.swing.JPasswordField();
	JOptionPane content;
	
	public AuthorizationDialog(Frame parent) {
		super(parent, true);
		setTitle("Authorization");
		setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		content = new JOptionPane(
			new Object[] {"username:",_uid,"password:",_pwd},
			JOptionPane.QUESTION_MESSAGE,
			JOptionPane.OK_CANCEL_OPTION
		);
		setContentPane(content);
		pack();
		setResizable(false);
		content.addPropertyChangeListener(
		    new PropertyChangeListener() {
		        public void propertyChange(PropertyChangeEvent e) {
		            String prop = e.getPropertyName();
		            if (isVisible() && (e.getSource() == content) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
		                setVisible(false);
		            }
		        }
		    }
		);
	}
	
	public int getValue() {
		return ((Integer)content.getValue()).intValue();
	}

	public String[] getAuth() {
		return new String[] {_uid.getText(),new String(_pwd.getPassword())};
	}
}
